/*
  LCD1602 I2C
 */

#ifndef LCD1602A_I2C_DHT11_H
#define LCD1602A_I2C_DHT11_H

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "component_dht11.h"
#include "component_ultrasonic.h"

long previousMillis_display;
const int interval_display = 1000;

LiquidCrystal_I2C lcd(0x27, 16, 2);  // 配置LCD地址及行列

void setup_lcd1602a_i2c() {
  lcd.init();                   // 初始化LCD
  lcd.backlight();              // 打开背光
  lcd.setCursor(0, 0);          // 设置显示位置
  lcd.print("Welcome To");      // 显示字符数据
  lcd.setCursor(0, 1);          // 设置显示位置
  lcd.print(" Arduino World");  // 显示字符数据
  delay(1000);
}

void loop_lcd1602a_i2c() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis_display >= interval_display) {
    previousMillis_display = currentMillis;  // Remember the time
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("T: ");
    lcd.print(temperature);
    lcd.setCursor(6, 0);
    lcd.print("H: ");
    lcd.print(humidity);
  };
  lcd.setCursor(0, 1);
  lcd.print("Distance: ");
  lcd.print(distance);
}

#endif /*  LCD1602A_I2C_DHT11_H */